<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>Practice</title>
    <script src="https://unpkg.com/react@16/umd/react.development.js"></script>
    <script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
    
    <!-- Don't use this in production: -->
    <script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script>
  </head>
  <body>
    
  有几点需要注意:
  return的时候需要用{} 括住sidebar, 不能使用<sidebar/>，因为sidebar是一个对象，而不是一个component,在JSX中使用js语法需要{}
  注意在map一个array或者list的时候，每个只能返回一个元素，所以用div包上了 h3 和 p
    <div id="root"></div>

    <script type="text/babel">

function Blog(props){
  let posts = props.posts;
  let sidebar = <ul>{posts.map((post)=> <li key={post.id}>{post.title}</li>)}</ul>;
  let content = posts.map(post=> <div key={post.id}><h3>{post.title}</h3><p>{post.content}</p></div>)
  return(
    <div>
      {sidebar}
      <hr />
      {content}
    </div>
  );
}

const posts = [
  {id: 1, title: 'Hello World', content: 'Welcome to learning React!'},
  {id: 2, title: 'Installation', content: 'You can install React from npm.'}
];
ReactDOM.render(
  <Blog posts={posts} />,
  document.getElementById('root')
);
    </script>
    <!--
      Note: this page is a great way to try React but it's not suitable for production.
      It slowly compiles JSX with Babel in the browser and uses a large development build of React.

      Read this section for a production-ready setup with JSX:
      https://reactjs.org/docs/add-react-to-a-website.html#add-jsx-to-a-project

      In a larger project, you can use an integrated toolchain that includes JSX instead:
      https://reactjs.org/docs/create-a-new-react-app.html

      You can also use React without JSX, in which case you can remove Babel:
      https://reactjs.org/docs/react-without-jsx.html
    -->
  </body>
</html>